/**
 * Graph module
 */

import React from 'react';
import tool from '../../../../../utils/tool';

class Graph extends React.Component {
    componentDidMount() {
        this.initElements();
    }
    initElements() {
        const { widget, preview } = this.props;
        // const { showPreview: isPreview } = preview;
        const isPreview  = 0;
        const prefix = isPreview ? 'preview-wgt-id-' : 'wgt-id-';
        this.elements = {
            graph: $(`#${prefix}${widget.id}`).find('.widget-graph'),
        };
    }
    reDraw() {
        const widget = this.props.widget;
        const DEFAULT_SHAPE = 'rectangle';
        tool.updateGShape(this, widget.gshap || DEFAULT_SHAPE);
    }
    render() {
        const widget = this.props.widget;

        const gradColor = tool.converionColor(widget.color);
        const grad = `linear-gradient(140deg, rgb(${gradColor.R},${gradColor.G},${gradColor.B}),#${widget.color})`;
        return (
          <del
            className="prevent-interaction widget-graph"
            style={{ fontSize: widget.t_font_size, fontFamily: widget.t_font_family }}
          >
            <div style={{ borderRadius: `${widget.radius}px`, background: grad, height: '100%', opacity: widget.opacity }} />
          </del>
        );
    }
}
Graph.defaultProps = {
    name: "graph",
    type: 12,
    width: 45,
    height: 45,
    color: "f76b1c",
    type_display:$._("Graph"),
    icon_class: "icon-square"
}
module.exports = Graph;
